package com.company.LKRace;

import java.util.*;

public class LX {
    public static void main(String[] args) {
        System.out.println(Runtime.getRuntime().availableProcessors());
    }
    public List<Integer> findKDistantIndices(int[] nums, int key, int k) {
        List<Integer> list = new ArrayList<>();
        List<Integer> temp = new ArrayList<>();
        for(int i =0;i<nums.length;i++){
            if(nums[i]==key){
                temp.add(i);
            }
        }
        for (int i = 0; i <nums.length ; i++) {
            for(int j =0;j<temp.size();j++){
                if(Math.abs(i-temp.get(j))<=k){
                    list.add(i);
                    break;
                }
            }
        }
        return list;
    }
    public static int digArtifacts(int n, int[][] artifacts, int[][] dig) {
        int x = 0;
        boolean[][] booleans = new boolean[n][n];
        for(int i =0;i<dig.length;i++){
            booleans[dig[i][0]][dig[i][1]] = true;
        }
        for(int i =0;i<artifacts.length;i++){
            boolean  temp = true;
            for(int j = artifacts[i][0];j<artifacts[i][2];j++){
                for(int z = artifacts[i][1];z<artifacts[i][3];z++){
                    if(!booleans[j][z]){
                        temp = false;
                        break;
                    }
                }
            }
            if(temp)x++;
        }
        return x;
    }
    public int maximumTop(int[] nums, int k) {
        if(k==0)return nums[0];
        Stack<Integer> stack = new Stack<>();
        for (int i = nums.length-1; i >=0 ; i--) {
            stack.add(nums[i]);
        }
        if(k<nums.length){
            int temp = Integer.MIN_VALUE;
            for(int i=0;i<k;i++){
                int x = stack.pop();
               temp = Math.max(temp,x);
            }
            if(temp<stack.lastElement())return stack.pop();
            return temp;
        }else if(k==nums.length){
            int temp = Integer.MIN_VALUE;
            for(int i=0;i<k-1;i++){
                int x = stack.pop();

                    temp = Math.max(temp,x);
            }
            return temp==Integer.MIN_VALUE? -1: temp;
        }else{
            int temp = Integer.MIN_VALUE;
            for(int i=0;i<nums.length-1;i++){
                int x = stack.pop();
                temp = Math.max(temp,x);
            }
            if(temp<stack.lastElement())return stack.pop();
            return temp==Integer.MIN_VALUE? -1: temp;
        }

    }
}
